
package cn;


import java.util.Calendar;
import java.util.Date;

public class DateDemo {
    public static void main(String[] args) {
        //java.util.Date 日期类
        Date d = new Date();
        System.out.printf("%tF %<tT%n",d);
        System.out.printf("%tF %<tT%n",d.getTime());
        System.out.printf("%tF %<tT %<tp %<tA%n",d);

        long time = d.getTime();
        System.out.println(time);

        //java.util.Calendar 日历类
        Calendar c = Calendar.getInstance();
        //日历类获取时间戳long类型的整数
        System.out.println(c.getTimeInMillis());

        //实现了Calendar类实例转换为Date类实例
        Date d2 = new Date(c.getTimeInMillis());

        //是将Date类实例转换为Calendar类实例
        //c.setTime(d);
        //c.setTimeInMillis(time);

        //将Calendar类转换为Date类
        Date d3 = c.getTime();
        //c.add();
        //c.set();
        //c.get();

        System.out.printf("%tF %<tT%n",c);
        System.out.printf("%tF %<tT%n",c.getTime());
        System.out.printf("%tF %<tT %<tp %<tA%n",c.getTimeInMillis());

        System.out.println("-------------");
        //指定 1985 12 3 20 30 15
        c.set(1985, Calendar.DECEMBER,3,20,30,15);
        System.out.printf("%tF %<tT%n",c);
    }
}
